/*
Date: October 2025
Project: Income and Child Maltreatment: Evidence from a Discontinuity in Tax Benefits
Author: Katherine Rittenhouse
Purpose: Use Treasury data to show EITC disbursement timing (Figure A2)
*/

clear all
set more off


***data import***
forval yr = 16/17 {
    forval month = 1/9 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts0`month'`yr'.xls mts0`month'`yr'.xls
	}
    forval month = 10/12 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts`month'`yr'.xls mts`month'`yr'.xls
	}
}

copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts0216.xlsx mts0216.xls


forval yr = 10/14 {
    forval month = 1/9 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts0`month'`yr'.txt mts0`month'`yr'.txt
	}
    forval month = 10/12 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts`month'`yr'.txt mts`month'`yr'.txt
	}
}

local yr 15 
    forval month = 1/2 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts0`month'`yr'.txt mts0`month'`yr'.txt
	}
	forval month = 3/4 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts0`month'`yr'.xlsx mts0`month'`yr'.xls
	}
	forval month = 5/9 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts0`month'`yr'.xlsx mts0`month'`yr'.xls
	}
	forval month = 10/12 {
		capture noisily copy https://www.fiscal.treasury.gov/files/reports-statements/mts/mts`month'`yr'.xls mts`month'`yr'.xls
	}

***data append***


clear all 
save monthlybenefits.dta,replace emptyok

forval yr = 0/9 {
    forval month = 1/9 {
		import delim mts0`month'0`yr'.txt,clear
		keep v1
		keep if strpos(v1,"EARNED INCOME")>1 | strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		keep if _n<3
		replace v1 = subinstr(v1,"......","x",.)
		split v1,parse("x")
		replace v1 = "EITC" if strpos(v1,"EARNED INCOME")>1
		replace v1 = "CTC" if strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		ren v1 credit
		ren v12 millions
		keep credit millions
		gen month = "0`month'"
		gen year = "0`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
		
	}
    forval month = 10/12 {
		import delim mts`month'0`yr'.txt,clear
		keep v1
		keep if strpos(v1,"EARNED INCOME")>1 | strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		keep if _n<3
		replace v1 = subinstr(v1,"......","x",.)
		split v1,parse("x")
		replace v1 = "EITC" if strpos(v1,"EARNED INCOME")>1
		replace v1 = "CTC" if strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		ren v1 credit
		ren v12 millions
		keep credit millions
		gen month = "`month'"
		gen year = "0`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
	}
}



forval yr = 10/14 {
    forval month = 1/9 {
		import delim mts0`month'`yr'.txt,clear
		keep v1
		keep if strpos(v1,"EARNED INCOME")>1 | strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		keep if _n<3
		replace v1 = subinstr(v1,"......","x",.)
		split v1,parse("x")
		replace v1 = "EITC" if strpos(v1,"EARNED INCOME")>1
		replace v1 = "CTC" if strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		ren v1 credit
		ren v12 millions
		keep credit millions
		gen month = "0`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 	
		}
    forval month = 10/12 {
		import delim mts`month'`yr'.txt,clear
		keep v1
		keep if strpos(v1,"EARNED INCOME")>1 | strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		keep if _n<3
		replace v1 = subinstr(v1,"......","x",.)
		split v1,parse("x")
		replace v1 = "EITC" if strpos(v1,"EARNED INCOME")>1
		replace v1 = "CTC" if strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		ren v1 credit
		ren v12 millions
		keep credit millions
		gen month = "`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
		}
}

local yr 15
    forval month = 1/2 {
		import delim mts0`month'`yr'.txt,clear
		keep v1
		keep if strpos(v1,"EARNED INCOME")>1 | strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		keep if _n<3
		replace v1 = subinstr(v1,"......","x",.)
		split v1,parse("x")
		replace v1 = "EITC" if strpos(v1,"EARNED INCOME")>1
		replace v1 = "CTC" if strpos(v1, "CHILD CREDIT")>1 | strpos(v1, "CHILD TAX CREDIT")>1
		ren v1 credit
		ren v12 millions
		keep credit millions
		gen month = "0`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 	
		}
	forval month = 3/9 {
		import excel mts0`month'`yr'.xls,clear sheet("Table 5")
		keep if strpos(A,"Earned Income")>1 | strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		replace A = "EITC" if strpos(A,"Earned Income")>1 
		replace A = "CTC" if strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		ren A credit
		ren B millions 
		gen month = "0`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
	}
	forval month = 10/12 {
		import excel mts`month'`yr'.xls,clear sheet("Table 5")
		keep if strpos(A,"Earned Income")>1 | strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		replace A = "EITC" if strpos(A,"Earned Income")>1 
		replace A = "CTC" if strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		ren A credit
		ren B millions 
		gen month = "`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
	}
		
local yr 16
		forval month = 1/9 {
		import excel mts0`month'`yr'.xls,clear sheet("Table 5")
		keep if strpos(A,"Earned Income")>1 | strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		replace A = "EITC" if strpos(A,"Earned Income")>1 
		replace A = "CTC" if strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		ren A credit
		ren B millions 
		gen month = "0`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
	}
		forval month = 10/12 {
		import excel mts`month'`yr'.xls,clear sheet("Table 5")
		keep if strpos(A,"Earned Income")>1 | strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		replace A = "EITC" if strpos(A,"Earned Income")>1 
		replace A = "CTC" if strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		ren A credit
		ren B millions 
		gen month = "`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save "monthlybenefits.dta",replace 
	}


local yr 17
		forval month = 1/9 {
		import excel mts0`month'`yr'.xls,clear sheet("Table 5")
		keep if strpos(A,"Earned Income")>1 | strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		replace A = "EITC" if strpos(A,"Earned Income")>1 
		replace A = "CTC" if strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		ren A credit
		ren B millions 
		gen month = "0`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save"monthlybenefits.dta",replace 
	}
		forval month = 10/12 {
		import excel mts`month'`yr'.xls,clear sheet("Table 5")
		keep if strpos(A,"Earned Income")>1 | strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		replace A = "EITC" if strpos(A,"Earned Income")>1 
		replace A = "CTC" if strpos(A, "Child Credit")>1 | strpos(A, "Child Tax Credit")>1
		ren A credit
		ren B millions 
		gen month = "`month'"
		gen year = "`yr'"
		append using "monthlybenefits.dta"
		save"monthlybenefits.dta",replace 
	}

keep credit millions month year
save "monthlybenefits.dta",replace 

gen nummill = subinstr(millions,",","",.)
replace year = "20"+year 


destring month year nummill ,force replace

gen ym = ym(year,month)

collapse (mean) nummill,by(month credit)

twoway (scatter nummill month if credit=="EITC")
twoway (scatter nummill month if credit=="CTC")

reshape wide nummil,i(month) j(credit) string
graph bar nummillEITC nummillCTC, ytitle("Outlays (millions)") over(month,relabel(1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun" 7 "Jul" 8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec" )) legend(label(1 "EITC") label(2 "CTC")) scheme(s1mono)
graph export "monthlybenefits.pdf", as(pdf) name("Graph")

























